package com.zq.rabbitmq.servcie;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FanoutSernderServicelmpl implements SenderService{

    @Autowired
    private AmqpTemplate amqpTemplate;
    @Autowired
    private ObjectMapper objectMapper;

    @Override
    public void sendbyte(byte[] bytes) {
        amqpTemplate.convertAndSend("fanoutEx", null, new String(bytes));
    }

    @Override
    public void sendString(String str) {
        amqpTemplate.convertAndSend("fanoutEx",null,str);
    }

    @Override
    public void sendObject(Object object) throws JsonProcessingException {
        String jsonString = objectMapper.writeValueAsString(object);
        amqpTemplate.convertAndSend("fanoutEx", null, jsonString);
    }
}
